package com.sixkey.controller.app;

import com.sixkey.entity.Evaluation;
import com.sixkey.response.Response;
import com.sixkey.service.IEvaluationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * ClassName: ApiEvaluationController
 * Package: com.sixkey.controller.api
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2023/10/17 - 23:59
 * @Version: v1.0
 */

/**
 * 用户评价
 */
@Slf4j
@Validated
@CrossOrigin
@RestController
@RequestMapping("/api/evaluation")
@RequiredArgsConstructor
public class ApiEvaluationController {

    private final IEvaluationService evaluationService;

    /**
     * 查询用户评价
     * @param
     * @return
     */
    @GetMapping("/list")
    public Response list(){
        log.info("查询用户评价请求进来~~~~");
        List<Evaluation> list = evaluationService.getEvaluation();
        return Response.success(list);
    }

    /**
     * 用户评价保存
     * @param evaluation
     * @return
     */
    @PostMapping("/save")
    public Response save(@RequestBody @Valid Evaluation evaluation){
        log.info("用户评价保存请求进来~~~~");
        evaluationService.save(evaluation);
        return Response.success();
    }

    /**
     * 用户评价删除
     * @param
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Response remove(@PathVariable("id") int id){
        log.info("用户评价删除请求进来~~~~");
        evaluationService.removeById(id);
        return Response.success();
    }
}
